package com.itheima.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.pojo.Students;
import com.itheima.pojo.PageBean;
import com.itheima.service.StudentsService;
import com.itheima.mapper.StudentsMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
* @author VRMMO
* @description 针对表【students】的数据库操作Service实现
* @createDate 2025-03-26 20:16:29
*/
@Service
public class StudentsServiceImpl implements StudentsService{

    @Autowired
    private StudentsMapper studentsMapper;

    @Override
    public PageBean page(Integer page, Integer pageSize, String name, Short gender, Date birth) {
        //1. 设置分页参数
        PageHelper.startPage(page,pageSize);

        //2. 执行查询
        List<Students> studnetsList = studentsMapper.list(name, gender, birth);
        Page<Students> p = (Page<Students>) studnetsList;

        //3. 封装PageBean对象
        PageBean pageBean = new PageBean(p.getTotal(), p.getResult());
        return pageBean;
    }

    @Override
    public void delete(List<Integer> studentids) {
        studentsMapper.delete(studentids);
    }

    @Override
    public void insert(Students student) {
        studentsMapper.insert(student);
    }


    @Override
    public Students getById(Integer studentid) {
        return studentsMapper.getById(studentid);
    }

    @Override
    public void update(Students students) {

        studentsMapper.update(students);
    }
}




